using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;

namespace org.synthful.Windows.nativeInterfaces
{
    /// <summary>
    /// Offered under Apache Public Licence 2.0
    /// synthful.org
    /// blessedgeek [@] synthful.org
    /// </summary>
    static class Sound
    {
        public enum PlaySoundFlags
        {
            Synchronously = 0x0000,
            Asynchronously = 0x0001,
            NoDefault = 0x0002,
            Memory = 0x0004,
            Loop = 0x0008,
            NoStop = 0x0010,
            NoWait = 0x00002000,
            Alias = 0x00010000,
            AliasId = 0x00110000,
            Filename = 0x00020000,
            Resource = 0x00040004,
            Purge = 0x0040,
            Application = 0x0080
        }

        /// <summary>
        /// Play a sound on system audio out
        /// </summary>
        /// <param name="lpszName"></param>
        /// <param name="hModule"></param>
        /// <param name="dwFlags"></param>
        [DllImport("winmm.dll")]
        private static extern bool PlaySound(string lpszName, int hModule, PlaySoundFlags dwFlags);


        /// <summary>
        /// Play a sound file on system audio out
        /// </summary>
        /// <param name="fileName"></param>
        /// <param name="playFlags"></param>
        public static void PlayASound(String fileName, PlaySoundFlags playFlags)
        {
            if (fileName.Length > 0)
            {
                PlaySound(fileName, 0, playFlags);
            }
        }

        /// <summary>
        /// Play a sound file on system audio out asyncrhronously
        /// </summary>
        /// <param name="fileName"></param>
        /// <param name="playFlags"></param>
        public static void PlayASound(String fileName)
        {
            PlayASound(fileName, PlaySoundFlags.Asynchronously);
        }
    }
}